<?php 

require_once '../mysqlConnect.php';

if (isset($_POST)) {

	$returnArray = array();
	
	if ($_POST['patientId'] == null || $_POST['patientId'] == "") {
		$returnArray[] = 'error';
		$returnArray[] = "patientId";	
	}
	elseif ($_POST['dateDiagnosed'] == null || $_POST['dateDiagnosed'] == "") {
		$returnArray[] = 'error';
		$returnArray[] = "dateDiagnosed";
	}
	elseif ($_POST['DOB'] == null || $_POST['DOB'] == "") {
		$returnArray[] = 'error';
		$returnArray[] = "DOB";	
	}
				
	if (count($returnArray) > 0)
		echo json_encode($returnArray);
	else {
		
		$sql = "UPDATE Patient SET PatID = '" . $_POST['patientId'] . "', DOB = '" . $_POST['DOB'] . "', Gender = '" . $_POST['selectGender'] . "', " . 
		"RelationshipStatus = '" . $_POST['selectRelationship'] . "', OccupationStatus = '" . $_POST['selectOccupation'] . "', WorkHabitat = '" . $_POST['selectTickWorkEnv'] . "', " . 
		"HuntHabitat = '" . $_POST['selectTickHuntEnv'] . "', PlayHabitat = '" . $_POST['selectTickPlayEnv'] . "', GardenHabitat = '" . $_POST['selectTickGardenEnv'] . "', " . 
		"DateDiagnosed = '" . $_POST['dateDiagnosed'] . "', TickBite = '" . $_POST['selectTickBite'] . "', Rash = '" . $_POST['selectRash'] . "' " . 
		"WHERE ID = '" . $_POST['originalPatientId'] . "' LIMIT 1";		
		
		$conn = GetConnection();
		$conn->query($sql);
		if ($conn->connect_errno)
			$returnArray[] = 'error';
		elseif ($conn->error)
			$returnArray[] = 'error';
		else
			$returnArray[] = 'success';
		
		echo json_encode($returnArray);
	
	}
}